local hx__zhiheng_shi = fk.CreateSkill {
  name = "hx__zhiheng_shi",
  tags = { Skill.Switch ,Skill.Compulsory },
}
hx__zhiheng_shi:addEffect(fk.AfterCardsMove, {
  anim_type = "switch",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(hx__zhiheng_shi.name) then
      for _, move in ipairs(data) do
        if move.from == player and (move.moveReason == fk.ReasonUse or move.moveReason == fk.ReasonResponse) and
        table.find(move.moveInfo, function(info)
          return info.fromArea == Card.PlayerHand
        end) then
          if player:getSwitchSkillState(hx__zhiheng_shi.name, false) == fk.SwitchYang then
            return true
          else
            return player:getMark("hx__zhiheng_shi_count") > 1
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if player.phase == Player.Play then
      room:addPlayerMark(player, "@hx__zhiheng_shi_reset", 1)
      if player:getMark("@hx__zhiheng_shi_reset") > 1 then
        room:setPlayerMark(player, "@hx__zhiheng_shi_reset", 0)
        room:addPlayerMark(player, "@hx__zhaowei_shi_skill-turn", 1)
      end
    end
    if player:getSwitchSkillState(hx__zhiheng_shi.name, true) == fk.SwitchYang then
      player:drawCards(2, hx__zhiheng_shi.name)
      room:addPlayerMark(player, "hx__zhiheng_shi_yang", 1)
    else
      room:setPlayerMark(player, "hx__zhiheng_shi_count", 0)
      room:setPlayerMark(player, "hx__zhiheng_shi_yang", 0)
      if #player:getCardIds{Player.Hand, Player.Equip} == 0 then return end
      room:askToDiscard(player, {
        min_num = 1,
        max_num = 2,
        include_equip = true,
        skill_name = hx__zhiheng_shi.name,
        prompt = "请弃置一至两张牌",
        cancelable = false,
      })
    end
  end,
})


hx__zhiheng_shi:addEffect(fk.CardUsing, {
  priority = 1,
  mute = true,
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill(hx__zhiheng_shi.name) and 
      player:getMark("hx__zhiheng_shi_yang") > 0 and data:isUsingHandcard(player)
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:addPlayerMark(player, "hx__zhiheng_shi_count", 1)
  end,
})

hx__zhiheng_shi:addEffect(fk.CardResponding, {
  priority = 1,
  mute = true,
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill(hx__zhiheng_shi.name) and 
      player:getMark("hx__zhiheng_shi_yang") > 0 and data:isUsingHandcard(player)
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:addPlayerMark(player, "hx__zhiheng_shi_count", 1)
  end,
})

return hx__zhiheng_shi